﻿@model SCMS.UI.Models.SalaryPayment
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "popup-page",
      LoadingElementId = "popup-loading",
      HttpMethod = "Post",
      Url = Url.Action("ApproveSPM"),
      OnBegin = "return VerifyBLBalance(" + Model.SalaryPaymentItems.Count + ")",
      OnSuccess = "ReviewComplete('SPM approved successfully.', 'Approval Complete')"
  };}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    
@using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
{
    @Html.ValidationSummary(true)
    <h4 style="text-align: center;">SALARY PAYMENT FORM</h4>
    <center><b>No. @Model.EntitySalaryP.RefNumber</b></center>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center" width="33%">
                Payroll Month
            </th>
            <th align="center" width="33%">
                Payroll Year
            </th>
            <th align="center" width="34%">
                Date
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntitySalaryP.PayrollMonth
                @Html.HiddenFor(s => s.EntitySalaryP.Id)
            </td>
            <td align="center">
                @Model.EntitySalaryP.PayrollYear
            </td>
            <td align="center">
                @Model.EntitySalaryP.PayrollDate.Value.ToString("dd/MM/yyyy")
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Office
            </th>
            <th align="center">
                Currency
            </th>
            <th align="center">
                Total Payroll Payment
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntitySalaryP.CountrySubOffice.Location.Name
            </td>
            <td align="center">
                @Model.EntitySalaryP.Currency.ShortName
            </td>
            <td align="center">
                @Html.TextBoxFor(m => m.EntitySalaryP.TotalPayroll, new { @id = "totalVal", @class = "numericTb", @readonly = "readonly" })
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Subject/Purpose:
            </td>
            <td colspan="2">
                <b>@Model.EntitySalaryP.Subject</b>
            </td>
        </tr>
    </table>
    <p id="budgetCheckStatus"></p>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th colspan="5" align="center">
                Payroll Details
            </th>
        </tr>
        <tr class="gridheader">
            <th colspan="2">
                Payroll Item
            </th>
            <th>
                Project No
            </th>
            <th>
                Budget Line
            </th>
            <th>
                Amount
            </th>
        </tr>        
        @{
              int num = 0; string pbDiv = ""; string rowId = "";
              for (int i = 0; i < Model.SalaryPaymentItems.Count; i++)
              {
                num = i + 1;
                pbDiv = "PBlines" + num;
                rowId = "row" + i;
                <tr id="@rowId">
                    <td style="text-align: left;" colspan="2">
                        @Model.SalaryPaymentItems[i].EntitySalaryPBL.PayrollItem.Name
                        @Html.HiddenFor(s => Model.SalaryPaymentItems[i].EntitySalaryPBL.Id)
                    </td>
                    <td>
                        @Html.DropDownListFor(e => Model.SalaryPaymentItems[i].ProjectDonorId, Model.SalaryPaymentItems[i].ProjectNos, new { @onchange = "javascript:onChangeProjectNoForSPM(this," + num + ")" })
                    </td>
                    <td>
                        <div id="@pbDiv">
                            @Html.DropDownListFor(e => Model.SalaryPaymentItems[i].BudgetLineId, Model.SalaryPaymentItems[i].BudgetLines, new { onchange = "javascript:checkBalance4Review(this)" })
                            @Html.ValidationMessageFor(e => Model.SalaryPaymentItems[i].BudgetLineId)
                        </div>
                    </td>
                    <td>
                        @Html.TextBoxFor(s => Model.SalaryPaymentItems[i].EntitySalaryPBL.Amount, new { @id = "totalPrice" + i, @class = "numericTb", @onblur = "javascript:calculateTotalsSPM(" + i + ")" })
                        @Html.ValidationMessageFor(s => Model.SalaryPaymentItems[i].EntitySalaryPBL.Amount)
                    </td>
                </tr>
              }
        } 
        <tr>
            <td colspan="2" class="gridheader" align="right">
                Currency of SPM
            </td>
            <td align="center">
                @Model.EntitySalaryP.Currency.ShortName
                <input type="hidden" id="currencyId" value="@Model.EntitySalaryP.Currency.Id.ToString()" />
            </td>
            <td class="gridheader" align="right">
                Total
            </td>
            <td align="right">
                @Html.TextBoxFor(e => e.EntitySalaryP.TotalPayroll, new { @id = "totalAmount", @class = "numericTb", @readonly = "readonly" })
            </td>
            <td align="right">
                
            </td>
        </tr>
        <tr>
            <td colspan="2" class="gridheader3" align="right">
                MB Currency
            </td>
            <td align="center">
                @Html.DropDownListFor(e => e.MBCurrencyId, Model.Currencies, new { @class = "smallControl", @id = "mbCurrencyId", @onchange = "calculateMBValue()" })
            </td>
            <td class="gridheader3" align="right">
                Master Budget Value
            </td>
            <td align="right">
                @Html.TextBoxFor(e => e.MBValue, new { @id = "mbValue", @class = "numericTb" })
                <input type="hidden" id="origLocalValue" />
                <input type="hidden" id="origFxValue" />
                <input type="hidden" id="spmItemCount" value="@Model.SalaryPaymentItems.Count" />
            </td>
        </tr>
    </table>    
    <table width="98%" align="center">
        <tr>
            <td width="50%" align="right">
                <input type="submit" value="Approve" class="btn tertiary" />
            </td>
            <td width="50%">
                <input type="button" class="btn tertiary" value=" Reject " onclick="sendRequest('/RequestReview/LoadRejectSPM/@Model.EntitySalaryP.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
            </td>
        </tr>   
    </table>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <td>
                Authorization
            </td>
            <td>
                SPM Prepared by
            </td>
            <td>
                Finance Review/Approval of BL/PN
            </td>
            <td>
                SPM Authorized by Manager/CD
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Name:
            </td>
            <td>
                @Model.EntitySalaryP.Staff2.Person.FirstName &nbsp;
                @Model.EntitySalaryP.Staff2.Person.OtherNames
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff3 != null)
                { 
                    @Model.EntitySalaryP.Staff3.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.EntitySalaryP.Staff3.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff1 != null)
                {                     
                    @Model.EntitySalaryP.Staff1.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.EntitySalaryP.Staff1.Person.OtherNames
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Title:
            </td>
            <td>
                 @Model.EntitySalaryP.Staff2.Designation.Name
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff3 != null)
                { 
                    @Model.EntitySalaryP.Staff3.Designation.Name
                }
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff1 != null)
                {                     
                    @Model.EntitySalaryP.Staff1.Designation.Name
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Date:
            </td>
            <td>@Model.EntitySalaryP.PreparedOn.Value.ToString("dd/MM/yyyy hh:mm tt")
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff3 != null)
                { 
                    @Html.DisplayFor(m => m.EntitySalaryP.ReviewedOn.FormatDDMMMYYYY())
                }
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff1 != null)
                {                     
                    @Html.DisplayFor(m => m.EntitySalaryP.AuthorizedOn.FormatDDMMMYYYY())
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Signature:
            </td>
            <td>
            </td>
            <td>
            </td>
            <td>
            </td>
        </tr>
    </table>
}
